package com.wpw.dream.thread;

import java.util.concurrent.TimeUnit;

public class MainThreadGroup {
	public static void main(String[] args) {
		Thread t = new Thread(new Runnable() {
			@Override
			public void run() {
				
				try {
					TimeUnit.SECONDS.sleep(1000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				
			}
		});
		t.setName("name");
		t.start();
		
		ThreadGroup threadGroup = Thread.currentThread().getThreadGroup();
		Thread[] list = new Thread[threadGroup.activeCount()];
		threadGroup.enumerate(list);
		for (Thread thread : list) {
			System.out.println(thread.getName());
			thread.interrupt();
		}
		//threadGroup.interrupt();
		System.out.println(threadGroup.activeCount());
		
		ThreadGroup runnable = new ThreadGroup("dd") {
			@Override
			public void uncaughtException(Thread t, Throwable e) {
			System.out.printf("The thread %s has thrown an Exception\n",t.getId());
			e.printStackTrace(System.out);
			System.out.printf("Terminating the rest of the Threads\n");
			interrupt();
			}
		};
		
		while ((threadGroup = threadGroup.getParent()) != null) {
			System.out.println(threadGroup.getName());
			
		}
	}

}
